/*
 * ResultSetMetaDataDemo.java
 *
 * Created on 2 de abril de 2005, 15:34
 */


package jdbc_02;

import jdbc_01.Conexion;

public class ResultSetMetaDataDemo {
    
    Conexion con;
    
    public ResultSetMetaDataDemo() {
        Conexion.driverOdbc();
        con = new Conexion("empleados", "empleados", "empleados");
        if (con.abrirConexion()) {
            mostrarMetaDatos();
            con.cerrarConexion();
        }        
    }

    void mostrarMetaDatos(){
        javax.swing.JTextArea jta = new javax.swing.JTextArea(10,40);
        try {
            java.sql.Statement stmt = con.getCon().createStatement();
            java.sql.ResultSet rset = stmt.executeQuery(
                "Select * from empleados" );
            java.sql.ResultSetMetaData rsmd = rset.getMetaData();
            
                jta.append("ColumnName\t");
                jta.append("TypeName\t");
                jta.append("isNull\t");
                jta.append("ClassName\n");
                
            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                jta.append(rsmd.getColumnName(i));
                jta.append("\t");
                jta.append(rsmd.getColumnTypeName(i));
                jta.append("\t");
                jta.append(String.valueOf(rsmd.isNullable(i)));   
                jta.append("\t");
                jta.append(rsmd.getColumnClassName(i));                
                jta.append("\n");
            }
            rset.close();
            stmt.close();
        } catch (java.sql.SQLException e) {
            jta.setText(e.getMessage());
        } finally {
            javax.swing.JOptionPane.showMessageDialog(null, 
                                new javax.swing.JScrollPane(jta));
        }
    }
    
    public static void main(String[] args) {
        new ResultSetMetaDataDemo();
        System.exit(0);
    }
}
